package com.example;

import java.io.*;

public class TxtSplit {
    public static void main(String[] args) {
        String sourceFileName = "/Users/xiaoxu.wu/Desktop/英语词库/RAM-20240808有效词库.txt";  // 源文件名
        int linesPerFile = 500;  // 每个文件的行数

        try (BufferedReader reader = new BufferedReader(new FileReader(sourceFileName))) {
            String line;
            int fileCount = 1;
            int lineCount = 0;
            BufferedWriter writer = null;

            while ((line = reader.readLine()) != null) {
                if (lineCount % linesPerFile == 0) {
                    if (writer != null) {
                        writer.close();
                    }
                    String newFileName = "/Users/xiaoxu.wu/Desktop/英语词库/output" + fileCount + ".txt";  // 新文件名
                    writer = new BufferedWriter(new FileWriter(newFileName));
                    fileCount++;
                }

                writer.write(line);
                writer.newLine();
                lineCount++;
            }

            if (writer != null) {
                writer.close();
            }

            System.out.println("拆分完成！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
